
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class Geo_CountryComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public Geo_CountryComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public Geo_Country SelectOne(int CountryID)
        {  
			PlacementManager.DAL.Geo_Country_DAL o = new PlacementManager.DAL.Geo_Country_DAL();
			o.CountryID = CountryID;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.Geo_Country Geo_CountryToReturn = new PlacementManager.Geo_Country((int)row["CountryID"], (string)row["CountryName"], (string)row["CountryCode"], (string)row["SubDivisionSingularName"], (string)row["SubDivisionPluralName"], (bool)row["Display"]);
				return Geo_CountryToReturn;
			}
			else
			{
				PlacementManager.Geo_Country Geo_CountryToReturnEmpty = new PlacementManager.Geo_Country();
                return Geo_CountryToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<Geo_Country> SelectAll(string sortExpression)
        {
            List<Geo_Country> listGeo_Country = new List<Geo_Country>();
            PlacementManager.DAL.Geo_Country_DAL o = new PlacementManager.DAL.Geo_Country_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listGeo_Country.Add(new Geo_Country((int)row["CountryID"], (string)row["CountryName"], (string)row["CountryCode"], (string)row["SubDivisionSingularName"], (string)row["SubDivisionPluralName"], (bool)row["Display"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listGeo_Country.Sort(new Geo_CountryComparer(sortExpression));
            return listGeo_Country;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(Geo_Country o)
        {	
            PlacementManager.DAL.Geo_Country_DAL oGeo_Country = new PlacementManager.DAL.Geo_Country_DAL();
			oGeo_Country.CountryName = o.CountryName;
			oGeo_Country.CountryCode = o.CountryCode;
			oGeo_Country.SubDivisionSingularName = o.SubDivisionSingularName;
			oGeo_Country.SubDivisionPluralName = o.SubDivisionPluralName;
			oGeo_Country.Display = o.Display;

            return oGeo_Country.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(string CountryName, string CountryCode, string SubDivisionSingularName, string SubDivisionPluralName, bool Display)
        {
            PlacementManager.DAL.Geo_Country_DAL oGeo_Country = new PlacementManager.DAL.Geo_Country_DAL();

			oGeo_Country.CountryName = CountryName;
			oGeo_Country.CountryCode = CountryCode;
			oGeo_Country.SubDivisionSingularName = SubDivisionSingularName;
			oGeo_Country.SubDivisionPluralName = SubDivisionPluralName;
			oGeo_Country.Display = Display;

            return oGeo_Country.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(Geo_Country o)
        {	
            PlacementManager.DAL.Geo_Country_DAL oGeo_Country = new PlacementManager.DAL.Geo_Country_DAL();
			oGeo_Country.CountryID = o.CountryID;
			oGeo_Country.CountryName = o.CountryName;
			oGeo_Country.CountryCode = o.CountryCode;
			oGeo_Country.SubDivisionSingularName = o.SubDivisionSingularName;
			oGeo_Country.SubDivisionPluralName = o.SubDivisionPluralName;
			oGeo_Country.Display = o.Display;

            return oGeo_Country.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int CountryID, string CountryName, string CountryCode, string SubDivisionSingularName, string SubDivisionPluralName, bool Display)
        {
            PlacementManager.DAL.Geo_Country_DAL oGeo_Country = new PlacementManager.DAL.Geo_Country_DAL();

			oGeo_Country.CountryID = CountryID;
			oGeo_Country.CountryName = CountryName;
			oGeo_Country.CountryCode = CountryCode;
			oGeo_Country.SubDivisionSingularName = SubDivisionSingularName;
			oGeo_Country.SubDivisionPluralName = SubDivisionPluralName;
			oGeo_Country.Display = Display;

            return oGeo_Country.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(Geo_Country o)
        {
            PlacementManager.DAL.Geo_Country_DAL oGeo_Country_DAL = new PlacementManager.DAL.Geo_Country_DAL();
            oGeo_Country_DAL.CountryID = o.CountryID;
            return oGeo_Country_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int CountryID)
        {
            PlacementManager.DAL.Geo_Country_DAL oGeo_Country_DAL = new PlacementManager.DAL.Geo_Country_DAL();
            oGeo_Country_DAL.CountryID = CountryID;
            return oGeo_Country_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>

	}
	
	public class Geo_CountryComparer : IComparer<Geo_Country>
    {
        private string _sortColumn;
        private bool _reverse;

        public Geo_CountryComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(Geo_Country a, Geo_Country b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "CountryID":
					retVal = String.Compare(a.CountryID.ToString(), b.CountryID.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CountryName":
					retVal = String.Compare(a.CountryName.ToString(), b.CountryName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CountryCode":
					retVal = String.Compare(a.CountryCode.ToString(), b.CountryCode.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "SubDivisionSingularName":
					retVal = String.Compare(a.SubDivisionSingularName.ToString(), b.SubDivisionSingularName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "SubDivisionPluralName":
					retVal = String.Compare(a.SubDivisionPluralName.ToString(), b.SubDivisionPluralName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Display":
					retVal = String.Compare(a.Display.ToString(), b.Display.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
